package com.ztz.mynewdemo.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.ztz.mynewdemo.R;
import com.ztz.mynewdemo.activity.TodayDetailActivity;
import com.ztz.mynewdemo.bean.TodayResponse;

import java.util.List;

/**
 * Created by wqewqe on 2017/5/18.
 */

public class TodayAdapter extends RecyclerView.Adapter<TodayAdapter.ViewHolder> {
    Context context;
    List<TodayResponse.ResultBean> resultBeanList;

    public TodayAdapter(Context context, List<TodayResponse.ResultBean> resultBeanList) {
        this.context = context;
        this.resultBeanList = resultBeanList;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.item_today,parent,false);
        final ViewHolder holder=new ViewHolder(view);
        holder.item.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int position=holder.getAdapterPosition();
                Intent intent=new Intent(context, TodayDetailActivity.class);
                intent.putExtra(TodayDetailActivity.DETAIL_ID,resultBeanList.get(position).get_id());
                context.startActivity(intent);
            }
        });
        return holder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        Glide.with(context).load(resultBeanList.get(position).getPic()).into(holder.ivToday);
        holder.tvTitle.setText(resultBeanList.get(position).getTitle());
        holder.tvDes.setText(resultBeanList.get(position).getDes());
        holder.tvYear.setText(resultBeanList.get(position).getYear()+""+"年");
        holder.tvMonth.setText(resultBeanList.get(position).getMonth()+""+"月");
        holder.tvDay.setText(resultBeanList.get(position).getDay()+""+"日");
        holder.tvLunar.setText(resultBeanList.get(position).getLunar());
    }

    @Override
    public int getItemCount() {
        return resultBeanList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        LinearLayout item;
        ImageView ivToday;
        TextView tvTitle;
        TextView tvDes;
        TextView tvYear;
        TextView tvMonth;
        TextView tvDay;
        TextView tvLunar;
        public ViewHolder(View view) {
            super(view);
            item=(LinearLayout)view;
            ivToday=(ImageView)view.findViewById(R.id.iv_today);
            tvTitle=(TextView)view.findViewById(R.id.today_title);
            tvDes=(TextView)view.findViewById(R.id.today_des);
            tvYear=(TextView)view.findViewById(R.id.tv_year);
            tvMonth=(TextView)view.findViewById(R.id.tv_month);
            tvDay=(TextView)view.findViewById(R.id.tv_day);
            tvLunar=(TextView)view.findViewById(R.id.tv_lunar);
        }
    }
}
